home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Magazine / GraphicsCards / StormMesa / src / FX / fxtris.c < prev    next >
C/C++ Source or Header  |  1999-02-04  |  7KB  |  243 lines

  1. /* -*- mode: C; tab-width:8;  -*-
  2.  
  3.              fxtris.c - 3Dfx VooDoo triangle functions 
  4. */
  5.  
  6. /*
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Library General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2 of the License, or (at your option) any later version.
  11.  *
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * Library General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU Library General Public
  18.  * License along with this library; if not, write to the Free
  19.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  *
  21.  * See the file fxapi.c for more informations about authors
  22.  *
  23.  */
  24.  
  25. #if defined(FX)
  26.  
  27. #include "fxdrv.h"
  28.  
  29. /************************************************************************/
  30. /*********************** Triangle functions *****************************/
  31. /************************************************************************/
  32.  
  33. #define GOURAUD(v) { \
  34.   fxMesa->gWin[(v)].r=(float) VB->Color[(v)][0]; \
  35.   fxMesa->gWin[(v)].g=(float) VB->Color[(v)][1]; \
  36.   fxMesa->gWin[(v)].b=(float) VB->Color[(v)][2]; \
  37.   fxMesa->gWin[(v)].a=(float) VB->Color[(v)][3]; \
  38. }
  39.  
  40. /************************************************************************/
  41.  
  42. static void fxTriangleSmooth(GLcontext *ctx, GLuint v1, GLuint v2, GLuint v3, GLuint pv)
  43. {
  44.   fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
  45.  
  46.   grDrawTriangle(&fxMesa->gWin[v1], &fxMesa->gWin[v2], &fxMesa->gWin[v3]);
  47. }
  48.  
  49. static void fxTriangleSmoothTwoSide(GLcontext *ctx, GLuint v1, GLuint v2, GLuint v3, GLuint pv)
  50. {
  51.   fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
  52.   struct vertex_buffer *VB=ctx->VB;
  53.  
  54.   GOURAUD(v1); 
  55.   GOURAUD(v2); 
  56.   GOURAUD(v3); 
  57.  
  58.   grDrawTriangle(&fxMesa->gWin[v1], &fxMesa->gWin[v2], &fxMesa->gWin[v3]);
  59. }
  60.  
  61. static void fxTriangleFlat(GLcontext *ctx, GLuint v1, GLuint v2, GLuint v3, GLuint pv)
  62. {
  63.   fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
  64.   GLubyte *Color=ctx->VB->Color[pv];
  65.  
  66.   grConstantColorValue(FXCOLOR(Color[0], Color[1], Color[2], Color[3]));
  67.  
  68.   grDrawTriangle(&fxMesa->gWin[v1], &fxMesa->gWin[v2], &fxMesa->gWin[v3]);
  69. }
  70.  
  71. /************************************************************************/
  72.  
  73. static void fxTriangleSmoothFrontBack(GLcontext *ctx, GLuint v1,
  74.                       GLuint v2, GLuint v3, GLuint pv)
  75. {
  76.   fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
  77.  
  78.   if(ctx->Color.ColorMask)
  79.     grColorMask(FXTRUE,FXFALSE);
  80.   else
  81.     grColorMask(FXFALSE,FXFALSE);
  82.   grDepthMask(FXFALSE);
  83.   grRenderBuffer(GR_BUFFER_BACKBUFFER);
  84.   grDrawTriangle(&fxMesa->gWin[v1], &fxMesa->gWin[v2], &fxMesa->gWin[v3]);
  85.  
  86.   if(ctx->Color.ColorMask)
  87.     grColorMask(FXTRUE,fxMesa->haveAlphaBuffer ? FXTRUE : FXFALSE);
  88.   else
  89.     grColorMask(FXFALSE,FXFALSE);
  90.   if(ctx->Depth.Mask)
  91.     grDepthMask(FXTRUE);
  92.   grRenderBuffer(GR_BUFFER_FRONTBUFFER);
  93.   grDrawTriangle(&fxMesa->gWin[v1], &fxMesa->gWin[v2], &fxMesa->gWin[v3]);
  94. }
  95.  
  96. static void fxTriangleSmoothTwoSideFrontBack(GLcontext *ctx, GLuint v1,
  97.                          GLuint v2, GLuint v3, GLuint pv)
  98. {
  99.   fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
  100.   struct vertex_buffer *VB=ctx->VB;
  101.  
  102.   GOURAUD(v1); 
  103.   GOURAUD(v2); 
  104.   GOURAUD(v3); 
  105.  
  106.   if(ctx->Color.ColorMask)
  107.     grColorMask(FXTRUE,FXFALSE);
  108.   else
  109.     grColorMask(FXFALSE,FXFALSE);
  110.   grDepthMask(FXFALSE);
  111.   grRenderBuffer(GR_BUFFER_BACKBUFFER);
  112.   grDrawTriangle(&fxMesa->gWin[v1], &fxMesa->gWin[v2], &fxMesa->gWin[v3]);
  113.  
  114.   if(ctx->Color.ColorMask)
  115.     grColorMask(FXTRUE,fxMesa->haveAlphaBuffer ? FXTRUE : FXFALSE);
  116.   else
  117.     grColorMask(FXFALSE,FXFALSE);
  118.   if(ctx->Depth.Mask)
  119.     grDepthMask(FXTRUE);
  120.   grRenderBuffer(GR_BUFFER_FRONTBUFFER);
  121.   grDrawTriangle(&fxMesa->gWin[v1], &fxMesa->gWin[v2], &fxMesa->gWin[v3]);
  122. }
  123.  
  124. static void fxTriangleFlatFrontBack(GLcontext *ctx, GLuint v1,
  125.                     GLuint v2, GLuint v3, GLuint pv)
  126. {
  127.   fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
  128.   GLubyte *Color=ctx->VB->Color[pv];
  129.  
  130.   grConstantColorValue(FXCOLOR(Color[0], Color[1], Color[2], Color[3]));
  131.  
  132.   if(ctx->Color.ColorMask)
  133.     grColorMask(FXTRUE,FXFALSE);
  134.   else
  135.     grColorMask(FXFALSE,FXFALSE);
  136.   grDepthMask(FXFALSE);
  137.   grRenderBuffer(GR_BUFFER_BACKBUFFER);
  138.   grDrawTriangle(&fxMesa->gWin[v1], &fxMesa->gWin[v2], &fxMesa->gWin[v3]);
  139.  
  140.   if(ctx->Color.ColorMask)
  141.     grColorMask(FXTRUE,fxMesa->haveAlphaBuffer ? FXTRUE : FXFALSE);
  142.   else
  143.     grColorMask(FXFALSE,FXFALSE);
  144.   if(ctx->Depth.Mask)
  145.     grDepthMask(FXTRUE);
  146.   grRenderBuffer(GR_BUFFER_FRONTBUFFER);
  147.   grDrawTriangle(&fxMesa->gWin[v1], &fxMesa->gWin[v2], &fxMesa->gWin[v3]);
  148. }
  149.  
  150. /************************************************************************/
  151.  
  152. static void fxAATriangleSmooth(GLcontext *ctx, GLuint v1, GLuint v2, GLuint v3, GLuint pv)
  153. {
  154.   fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
  155.  
  156.   grAADrawTriangle(&fxMesa->gWin[v1],&fxMesa->gWin[v2],&fxMesa->gWin[v3],
  157.            FXTRUE,FXTRUE,FXTRUE);
  158. }
  159.  
  160. static void fxAATriangleSmoothTwoSide(GLcontext *ctx, GLuint v1, GLuint v2, GLuint v3, GLuint pv)
  161. {
  162.   fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
  163.   struct vertex_buffer *VB=ctx->VB;
  164.  
  165.   GOURAUD(v1); 
  166.   GOURAUD(v2); 
  167.   GOURAUD(v3); 
  168.  
  169.   grAADrawTriangle(&fxMesa->gWin[v1],&fxMesa->gWin[v2],&fxMesa->gWin[v3],
  170.            FXTRUE,FXTRUE,FXTRUE);
  171. }
  172.  
  173. static void fxAATriangleFlat(GLcontext *ctx, GLuint v1, GLuint v2, GLuint v3, GLuint pv)
  174. {
  175.   fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
  176.   GLubyte *Color=ctx->VB->Color[pv];
  177.  
  178.   grConstantColorValue(FXCOLOR(Color[0],Color[1],
  179.                    Color[2],Color[3]));
  180.  
  181.   fxMesa->gWin[v1].a=fxMesa->gWin[v2].a=fxMesa->gWin[v3].a=(float)Color[3];
  182.  
  183.   grAADrawTriangle(&fxMesa->gWin[v1],&fxMesa->gWin[v2],&fxMesa->gWin[v3],
  184.            FXTRUE,FXTRUE,FXTRUE);
  185. }
  186.  
  187. /************************************************************************/
  188.  
  189. triangle_func fxDDChooseTriangleFunction(GLcontext *ctx)
  190. {
  191.   fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
  192.  
  193.   if((ctx->Polygon.OffsetAny) || /* Not yet supported */
  194.      (ctx->Polygon.StippleFlag))
  195.     return NULL;
  196.  
  197.   if(ctx->Polygon.SmoothFlag) {
  198.     if(ctx->Light.ShadeModel==GL_SMOOTH) {
  199.       if(ctx->Light.Model.TwoSide)
  200.     return fxAATriangleSmoothTwoSide;
  201.  
  202.       return fxAATriangleSmooth;
  203.     }
  204.  
  205.     return fxAATriangleFlat;
  206.   }
  207.  
  208.   if(ctx->RasterMask & FRONT_AND_BACK_BIT) {
  209.     if(ctx->Light.ShadeModel==GL_SMOOTH) {
  210.       if(ctx->Light.Model.TwoSide)
  211.     return fxTriangleSmoothTwoSideFrontBack;
  212.       
  213.       return fxTriangleSmoothFrontBack;
  214.     }
  215.  
  216.     return fxTriangleFlatFrontBack;
  217.   }
  218.  
  219.   if(ctx->Light.ShadeModel==GL_SMOOTH) {
  220.     if(ctx->Light.Model.TwoSide)
  221.       return fxTriangleSmoothTwoSide;
  222.  
  223.     return fxTriangleSmooth;
  224.   }
  225.  
  226.   return fxTriangleFlat;
  227. }
  228.  
  229.  
  230. #else
  231.  
  232.  
  233. /*
  234.  * Need this to provide at least one external definition.
  235.  */
  236.  
  237. int gl_fx_dummy_function_tris(void)
  238. {
  239.   return 0;
  240. }
  241.  
  242. #endif  /* FX */
  243.